package org.darcy.controller.portal.puzzle;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;

/**
 * 数学难题
 */
@Controller
@Api(value = "数学难题", tags = "数学难题")
@RequestMapping(value = "/puzzle")
@Slf4j
public class PuzzleController {

	private final String basePath = "puzzle/";

	/**
	 * 题目列表
	 */
	@GetMapping("list")
	public String list() {
		return basePath + "puzzleList";
	}

	/**
	 * 题目详情
	 */
	@GetMapping("detail/{id}")
	public String detail(ModelMap m, @PathVariable Integer id, Integer bookCount, Integer peopleCount) {
		log.debug("问题序号：{}", id);
		// 分发书本
		if (id == 4) {
			if (bookCount == null) {
				bookCount = 25;
			}
			if (peopleCount == null) {
				peopleCount = 5;
			}
			DispatchBook demo = new DispatchBook(bookCount, peopleCount);
			m.put("bookCount", bookCount);
			m.put("peopleCount", peopleCount);
			m.put("list", demo.dispatch());
			m.put("minBookCount", demo.getMinBookCount());
		}
		return basePath + "puzzleDetail";
	}

}
